package com.zmz.Stream;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * Create with IntelliT IDEA
 *
 * @Author: zhengmingzhe
 * @Date: 2022/07/31/19:21
 * @Description:  流可以进行合并，去重，限制，跳过等操作
 */
public class Stream13 {
    public static void main(String[] args) {
        String[] arr1 ={"a","b","c","d"};
        String[] arr2 ={"d","e","f","g"};

        //将两个数组合并   [a, b, c, d, d, e, f, g]
        List<String> collect = Stream.concat(Arrays.stream(arr1), Arrays.stream(arr2)).collect(Collectors.toList());
        System.out.println(collect);
        //合并并去重    [a, b, c, d, e, f, g]
        List<String> collect2 = Stream.concat(Arrays.stream(arr1), Arrays.stream(arr2)).distinct().collect(Collectors.toList());
        System.out.println(collect2);
        //合并去重并只显示前三个  [a, b, c]
        List<String> collect3 = Stream.concat(Arrays.stream(arr1), Arrays.stream(arr2)).distinct().limit(3).collect(Collectors.toList());
        System.out.println(collect3);
        //合并去重并只显示前三个 跳过一个元素获取  [b, c, d]
        List<String> collect4 = Stream.concat(Arrays.stream(arr1), Arrays.stream(arr2)).distinct().skip(1).limit(3).collect(Collectors.toList());
        System.out.println(collect4);
    }
}
